package Cm818_Zj_Mi;

import java.util.*;

/** 
 ������ѡ�Է���
*/
public class TwoTeam
{
	public TwoTeam()
	{
	}
	public final boolean TwoTeamManager(int ID, int CaiZID, String RightNumber, String Number, int ErXZuxuanMoney, String Manager, int zhushu, tangible.RefObject<String> CPNum, tangible.RefObject<Integer> ZjhCount)
	{
		final int ErXDan = 50120050; //������ѡ��ѡ
		final int ExXFu = 50120051; //������ѡ��ʽ
		final int ExFenWeiZX = 50120052; //������ѡ��λ��ѡ
		final int ZuXuanAll = 50120053; //������ѡ����
		final int ZuxuanBAoDAN = 50120054; //������ѡ����....


		String RightNumberErXZx = RightNumber; //������ѡ����ȷ��������


		switch (CaiZID)
		{
			case ErXDan:
			{
				return ToErXDan(ID, ErXDan, RightNumberErXZx, Number, ErXZuxuanMoney, Manager, zhushu, CPNum, ZjhCount);
			}
			case ExXFu:
			{
				return ToErXFushi(ID, ExXFu, RightNumberErXZx, Number, ErXZuxuanMoney, Manager, zhushu, CPNum, ZjhCount);
			}
			case ExFenWeiZX:
			{
				return ToErXFenWei(ID, ExFenWeiZX, RightNumberErXZx, Number, ErXZuxuanMoney, Manager, zhushu, CPNum, ZjhCount);
			}
			case ZuXuanAll:
			{
				return ToErXZuxuanBaodiani(ID, ZuXuanAll, RightNumberErXZx, Number, ErXZuxuanMoney, Manager, zhushu, CPNum, ZjhCount);
			}
			case ZuxuanBAoDAN:
			{
				return ToErXZuxuanBaoDan(ID, ZuxuanBAoDAN, RightNumberErXZx, Number, ErXZuxuanMoney, Manager, zhushu, CPNum, ZjhCount);
			}
		}
		return false;
	}

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region ������ϵ�ѡ
	//������ϵ�ѡ
	private boolean ToErXDan(int ID, int CaiZID, String RightNumberEZuxuan, String Number, int ErXZuxuanMoney, String Manager, int zhushu, tangible.RefObject<String> CPNum, tangible.RefObject<Integer> ZjhCount)
	{
		int zjs = 0;
		int templength = 0;
		boolean islast = false;
		int length = 0;
		if (ErXDanManagerRich(RightNumberEZuxuan, Number))
		{
//			templength++;
			ZjhCount.argValue++;
			zjs++;
			WinManager o = new WinManager();
			if (!o.ToManager(ID, ErXZuxuanMoney, RightNumberEZuxuan, Manager, zhushu, CPNum))
			{
				return false;
			}
		}
		else
		{
//			templength++;
			boolean hadEacn = false;
			NoWinManager nwm = new NoWinManager();
			if (zjs != 0)
			{
				hadEacn = true;
			}
			if (templength == length)
			{
				islast = true;
			}
			if (!nwm.ToManager(ID, islast, hadEacn, Manager))
			{
				return false;
			}
		}
		return true;
	}
	private boolean ErXDanManagerRich(String RightNumberEZuxuan, String Number)
	{
		if (RightNumberEZuxuan.equals(Number) || reverse(Number).equals(RightNumberEZuxuan))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region  ������ѡ��ʽ
	private boolean ToErXFushi(int ID, int CaiZID, String RightNumberEZuxuan, String Number, int ErXZuxuanMoney, String Manager, int zhushu, tangible.RefObject<String> CPNum, tangible.RefObject<Integer> ZjhCount)
	{

		int zjs = 0;
		int templength = 0;
		boolean islast = false;
		int length = 0;
		if (ErXFushiManagerRich(RightNumberEZuxuan, Number))
		{
//				templength++;
			ZjhCount.argValue++;
			zjs++;
			WinManager o = new WinManager();
			if (!o.ToManager(ID, ErXZuxuanMoney, RightNumberEZuxuan, Manager, zhushu, CPNum))
			{
				return false;
			}
		}
		else
		{
//			templength++;
			boolean hadEacn = false;
			NoWinManager nwm = new NoWinManager();
			if (zjs != 0)
			{
				hadEacn = true;
			}
			if (templength == length)
			{
				islast = true;
			}
			if (!nwm.ToManager(ID, islast, hadEacn, Manager))
			{
				return false;
			}
		}
		return true;

	}

	private boolean ErXFushiManagerRich(String RightNumberEZuxuan, String Number)
	{
		String ra = RightNumberEZuxuan.substring(0,1);
		String rb = RightNumberEZuxuan.substring(1, 2);
		if (ra.equals(rb))
		{
			return false;
		}
		ArrayList al = new ArrayList();
		for (int i = 0;i < Number.length();i++)
		{
			al.add(Number.charAt(i).toString());
		}
		for (int ii = 0;ii < al.size();ii++)
		{
			String tmp = al.get(ii).toString();
			if (ra.equals(tmp))
			{
				for (int iii = 0;iii < al.size();iii++)
				{
					String tmp2 = al.get(iii).toString();
					if (rb.equals(tmp2))
					{
						return true;
					}
				}
			}
		}

		return false;
	}
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region ���Ƿ�λ
	private boolean ToErXFenWei(int ID, int CaiZID, String RightNumberEZuxuan, String Number, int ErXZuxuanMoney, String Manager, int zhushu, tangible.RefObject<String> CPNum, tangible.RefObject<Integer> ZjhCount)
	{
		int zjs = 0;
		int templength = 0;
		boolean islast = false;
		int length = 0;
		boolean Dourich = false;
		tangible.RefObject<Boolean> tempRef_Dourich = new tangible.RefObject<Boolean>(Dourich);
		boolean tempVar = ErXFenWeiManagerRich(RightNumberEZuxuan, Number, tempRef_Dourich);
			Dourich = tempRef_Dourich.argValue;
		if (tempVar)
		{
	//		templength++;
			ZjhCount.argValue++;
			zjs++;
			WinManager o = new WinManager();
			if (Dourich == true)
			{
				ErXZuxuanMoney *= 2;
			}
			if (!o.ToManager(ID, ErXZuxuanMoney, RightNumberEZuxuan, Manager, zhushu, CPNum))
			{
				return false;
			}
		}
		else
		{
//		templength++;
			boolean hadEacn = false;
			NoWinManager nwm = new NoWinManager();
			if (zjs != 0)
			{
				hadEacn = true;
			}
			if (templength == length)
			{
				islast = true;
			}
			if (!nwm.ToManager(ID, islast, hadEacn, Manager))
			{
				return false;
			}
		}
		return true;

	}

	private boolean ErXFenWeiManagerRich(String RightNumberEZuxuan, String Number, tangible.RefObject<Boolean> DoubleRich)
	{
		String[] temp = Number.split("[,]", -1);
		int count = 0;
		ArrayList al1 = new ArrayList();
		ArrayList al2 = new ArrayList();
		ArrayList AL = new ArrayList();
		for (int x = 0; x < temp[0].length(); x++)
		{
			al1.add(temp[0].charAt(x).toString());
		}
		for (int y = 0;y < temp[1].length();y++)
		{
			al2.add(temp[1].charAt(y).toString());
		}

		for (String ax : al1)
		{
			for (String ay : al2)
			{
				//AL.Add(ax.ToString()+ay.ToString());
				AL.add(ax + ay);

				AL.add(ay + ax); //����������
			}
		}

		for (int res = 0;res < AL.size(); res++)
		{
			if (AL.get(res).toString().equals(RightNumberEZuxuan) || reverse(AL.get(res).toString()).equals(RightNumberEZuxuan))
			{
				count++;
//					if(RightNumberEZuxuan.Substring(0,1) == RightNumberEZuxuan.Substring(1,1) )
//					{
//						DoubleRich = true;
//						return true;
//					}
				if (AL.get(res).toString().equals(RightNumberEZuxuan) && reverse(AL.get(res).toString()).equals(RightNumberEZuxuan))
				{
					DoubleRich.argValue = true;
					return true;
				}
				return true;
			}
		}

		if (count == 0)
		{
			return false;
		}
		if (count >= 2)
		{
			DoubleRich.argValue = true;
		}
		return true;
	}
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region ��ѡ����
	private boolean ToErXZuxuanBaodiani(int ID, int CaiZID, String RightNumberEZuxuan, String Number, int ErXZuxuanMoney, String Manager, int zhushu, tangible.RefObject<String> CPNum, tangible.RefObject<Integer> ZjhCount)
	{
		int zjs = 0;
		int templength = 0;
		boolean islast = false;
		int length = 0;
		boolean Dourich = false;
		tangible.RefObject<Boolean> tempRef_Dourich = new tangible.RefObject<Boolean>(Dourich);
		boolean tempVar = ErXZuxuanBaoDianManagerRich(RightNumberEZuxuan, Number, tempRef_Dourich);
			Dourich = tempRef_Dourich.argValue;
		if (tempVar)
		{
			//templength++;
			ZjhCount.argValue++;
			zjs++;
			WinManager o = new WinManager();
			if (Dourich == true)
			{
				ErXZuxuanMoney *= 2;
			}
			if (!o.ToManager(ID, ErXZuxuanMoney, RightNumberEZuxuan, Manager, zhushu, CPNum))
			{
				return false;
			}
		}
		else
		{
			//templength++;
			boolean hadEacn = false;
			NoWinManager nwm = new NoWinManager();
			if (zjs != 0)
			{
				hadEacn = true;
			}
			if (templength == length)
			{
				islast = true;
			}
			if (!nwm.ToManager(ID, islast, hadEacn, Manager))
			{
				return false;
			}
		}
		return true;

	}

	private boolean ErXZuxuanBaoDianManagerRich(String RightNumberEZuxuan, String Number, tangible.RefObject<Boolean> DoubleRich)
	{
		//int count = 0;
		String ra = RightNumberEZuxuan.substring(0,1);
		String rb = RightNumberEZuxuan.substring(1, 2);
		int Right = Integer.parseInt(ra) + Integer.parseInt(rb);
		int temp = Integer.parseInt(Number);
		if (Right == temp)
		{
			if (ra.equals(rb))
			{
				DoubleRich.argValue = true;
				return true;
			}
			return true;
		}
		return false;

//			int count = 0;
//			string ra = RightNumberEZuxuan.Substring(0,1);
//			string rb = RightNumberEZuxuan.Substring(1,1);
//			int Right = int.Parse(ra)+int.Parse(rb);
//			string[] temp = Number.Split(',');
//			for(int i=0;i<temp.Length; i++)
//			{
//				int NumberiNT  = int.Parse(temp[i].ToString());
//	
//				if(Right == NumberiNT )
//				{
//					count ++ ;
//					if(ra==rb)
//						DoubleRich = true;
//				}
//				if(count != 0)
//					return true;
//				return false;
//			}
//			return false;
	}


//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion



//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region ������ѡ����
	private boolean ToErXZuxuanBaoDan(int ID, int CaiZID, String RightNumberEZuxuan, String Number, int ErXZuxuanMoney, String Manager, int zhushu, tangible.RefObject<String> CPNum, tangible.RefObject<Integer> ZjhCount)
	{
		int zjs = 0;
		int templength = 0;
		boolean islast = false;
		int length = 0;
		boolean Dourich = false;
		tangible.RefObject<Boolean> tempRef_Dourich = new tangible.RefObject<Boolean>(Dourich);
		boolean tempVar = ErXZuxuanBaoDanManagerRich(RightNumberEZuxuan, Number, tempRef_Dourich);
			Dourich = tempRef_Dourich.argValue;
		if (tempVar)
		{
	//		templength++;
			ZjhCount.argValue++;
			zjs++;
			WinManager o = new WinManager();
			if (Dourich == true)
			{
				ErXZuxuanMoney *= 2;
			}
			if (!o.ToManager(ID, ErXZuxuanMoney, RightNumberEZuxuan, Manager, zhushu, CPNum))
			{
				return false;
			}
		}
		else
		{
		//	templength++;
			boolean hadEacn = false;
			NoWinManager nwm = new NoWinManager();
			if (zjs != 0)
			{
				hadEacn = true;
			}
			if (templength == length)
			{
				islast = true;
			}
			if (!nwm.ToManager(ID, islast, hadEacn, Manager))
			{
				return false;
			}
		}
		return true;

	}


	private boolean ErXZuxuanBaoDanManagerRich(String RightNumberEZuxuan, String Number, tangible.RefObject<Boolean> DoubleRich)
	{
		int count = 0;

		String[] b = tangible.DotNetToJavaStringHelper.trimEnd(Number, ',').split("[,]", -1); // ���ܵ���..
		String a = RightNumberEZuxuan.substring(0,1);
		String bs = RightNumberEZuxuan.substring(1, 2);
		for (int i = 0; i < b.length; i++)
		{
			String temp = b[i].toString();
			if (a.equals(temp) || bs.equals(temp))
			{
				count++;
				if (a.equals(bs))
				{
					DoubleRich.argValue = true;
				}
				return true;
			}
		}
		if (count == 0)
		{
			return false;
		}
		return true;

	}



//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region �ߵ���λʮλ
	//�ߵ���λ&ʮλ
	private String reverse(String Temp)
	{
		String a = Temp.substring(0,1);
		String b = Temp.substring(1, 2);
		return b + a;
	}
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion


}